<template>
  <div>
    <j-modal
      title="评价管理"
      :width="1200"
      :visible="visible"
      :confirmLoading="confirmLoading"
      switchFullscreen
      @ok="plhandleOk"
      @cancel="plhandleCancel"
      cancelText="关闭"
      :footer="false"
    >

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery" :form="queryform">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="评论时间">
              <!-- <a-input placeholder="请输入帖子标题"  v-decorator="['time']"></a-input> -->
              <a-date-picker valueFormat='YYYY-MM-DD'  v-decorator="['time']" />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="关键词">
              <a-input placeholder="请输入帖子内容"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
     
      </a-form>
      <div>已选中{{num}}个<a-button type="primary" style="margin-left: 20px;" @click="Alledit">批量屏蔽</a-button></div>
      <br>
    </div>

      <!-- table区域-end -->
      <div>
        <a-table
         :columns="columns" 
         :dataSource="pldata.records"
         bordered
         rowKey="id"
         :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
         :pagination="ipaginations"
         @change="pageonchage"
         > 
         <span slot="isTop" slot-scope="text">
            {{text == 1 ? '置顶' : '默认'}}
         </span>
        <span slot="action" slot-scope="text,record,index">
          <a @click="reply(record.id)">回复</a>
          <a-divider type="vertical" />
            <a @click="handleZd(record.id,index)">{{record.isTop == 1 ? '置顶' : '取消置顶'}}</a>
          <a-divider type="vertical" />
          <a @click="handlePb(record.id,index)">{{record.status == 0 ? '屏蔽' : record.status == 1 ? '取消屏蔽' : ''}}</a>
        </span>
        </a-table>
        <hfModal ref="hfmodal" :parentlist="parentlist" @searchback="searchback"></hfModal>
      </div>
    </j-modal>
    
  </div>

</template>

<script>
 import { httpAction,getAction } from '@/api/manage'
 import hfModal from '../modules/hfModal'
//  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
export default {
  name: "plsysModel",
  // mixins:[JeecgListMixin],
  components:{ hfModal },
  props: {
    pldata: {
    //   type: Object,
      require: true,
    }
  },
  data() {
    return {
      visible: false,
      confirmLoading: false,
      selectedRowKeys: [],
      queryform:this.$form.createForm(this),//搜索表单
      num:0,
      columns: [
        {
          title: "评论者",
          dataIndex: "fromName",
          align: "center",
        },
        {
          title: "评论内容",
          dataIndex: "cover",
          align: "center",
        },
        {
          title: "评论时间",
          dataIndex: "createTime",
          align: "center",
        },
        {
          title: "置顶",
          dataIndex: "isTop",
          align: "center",
          scopedSlots: { customRender: 'isTop' },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: 'action' },
        },
      ],
      url:{
        zding:'/postComment/postComment/edit',
        editbatch:'/postComment/postComment/editbatch',
        listPC:'/PostReply/postReply/listPC'
      },
      alldata:[],
      parentlist:{},
      hfid:'',
      ipaginations:{
        current: 1,
        total: 0, // 总数
        showSizeChanger: true,
        showTotal: total => `共 ${total} 条` // 分页中显示总的数据
      }
    };
  },
  created(){
   
  },
  methods: {
    pageonchage(pagination){
      this.ipaginations.current = pagination.current // 重新设置当前页
      this.ipaginations.pageSize = pagination.pageSize
      // const params = {
      //   pageNo: pagination.current,
      //   pageSize: pagination.pageSize
      // }
      this.$parent.$parent.pageNo = pagination.current 
      this.$parent.$parent.pageSize = pagination.pageSize 
      // console.log(this.$parent.$parent.pageNo = pagination.current ,'params');
      this.$parent.$parent.isModal(this.$parent.$parent.plid)
    },
    //确定
    plhandleOk() {
      this.visible = false;
    },
    //取消
    plhandleCancel() {
      this.visible = false;
      this.alldata = []
      this.$parent.$parent.pageNo = '1'
      this.$parent.$parent.pageSize = '10'
    },
    //置顶
    handleZd(id,index)
    {
        let httpurl = this.url.zding
        let method = 'post'
        let params = {
        id:id,
        isTop:this.pldata.records[index].isTop == 0 ? 1 : 0
      }
        httpAction(httpurl,params,method).then((res)=>{
         this.$emit('callback')
        })
    },
    //屏蔽
    handlePb(id,index)
    {
        let httpurl = this.url.zding
        let method = 'post'
        let params = {
        id:id,
        status:this.pldata.records[index].status == 0 ? 1 : 0
      }
        httpAction(httpurl,params,method).then((res)=>{
         this.$emit('callback')
        })
    },
    //全选
    onSelectChange(selectedRowKeys,record) {
      let arr = []
      record.map((item)=>{
        arr.push({
          id:item.id,
          status:1
        })
      })

      console.log(arr,'arr');
      this.alldata = arr

      this.selectedRowKeys = selectedRowKeys;
      this.num = selectedRowKeys.length
    },
    //批量屏蔽
    Alledit(){
      let httpurl = this.url.editbatch
        let method = 'post'
        httpAction(httpurl,this.alldata,method).then((res)=>{
          if(res.code == 200)
          {
          this.$message.success(res.message)
            this.alldata = []
            this.$emit('callback')
          }
        })
    },
    //查询
    searchQuery(){
      const params = this.queryform.getFieldsValue(['time'])
      this.$emit('callback',params)
      console.log(params);
    },
    //重置
    searchReset(){
      this.queryform.resetFields()
      this.$emit('callback')
    },
    //回复
    reply(id,hf)
    {
      console.log(this,'this');
      this.hfid =  id
      this.$refs.hfmodal.visible = true
      const url = this.url.listPC
      const params = {
        parentId:id,
        toName:hf == undefined ? '' : hf.toName,
        replyTime:hf == undefined ? '' : hf.createTime,
      }
      getAction(url,params).then((res)=>{
          this.parentlist = res.result
      })
    },
    searchback(params){
      this.reply(this.hfid,params)
    }
  },
};
</script>

<style lang="less" scoped></style>
